package org.sam.beatles.config;

import javax.sql.DataSource;

import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.zaxxer.hikari.HikariDataSource;

/**
 * 数据库配置文件
 * 
 * @author sam
 *
 */
@Configuration
public class DataSourceConfigure {

	/**
	 * 数据库
	 * 
	 * @return
	 */
	@ConfigurationProperties(prefix = "spring.datasource")
	@Bean
	@Primary
	public DataSource memoryDataSource(DataSourceProperties properties) {
		return DataSourceBuilder.create(properties.getClassLoader())
				.type(HikariDataSource.class)
				.driverClassName(properties.determineDriverClassName())
				.url(properties.determineUrl())
				.username(properties.determineUsername())
				.password(properties.determinePassword())
				.build();
	}
}
